<?php
namespace frontend\models;

use Yii;
use yii\base\Model;
class UploadForm extends Model
{

	 public $compony_name;
	 public $compony_area;
	 public $content;
	 public $tel;
	 public $name;
	 public $status;
	 public $logo;
	 public function rules()
    { 
        return [
            [['compony_name', 'compony_area', 'content', 'tel', 'name'], 'required'],
            [['logo'],'file',
            'extensions'=>['jpg','png','gif'],'wrongExtension'=>'只能上传{extensions}类型文件！',
            'maxSize'=>1024*1024*5,'tooBig'=>'文件上传过大！',
            'skipOnEmpty'=>false,'uploadRequired'=>'请上传文件！',
            'message'=>'上传失败！'
         ]
           
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'compony_msg_id' => 'Compony Msg ID',
            'compony_name' => '公司名称',
            'compony_area' => '公司地址',
            'content' => '公司简介',
            'tel' => '联系人电话',
            'name' => '联系人姓名',
            'logo' => '公司Logo',
            'user_id' => 'User ID',
            'status' => 'Status',
        ];
    }
    public function upload()
    {
        if ($this->validate()) {
        	$this->logo->saveAs('upload/'.$this->logo->baseName.'.'.$this->logo->extension);
          	return 'upload/'.$this->logo->baseName.'.'.$this->logo->extension;
        }else{
            return false;
        }
    }
    public function getname()
    {
    	return 'upload/'.$this->logo->baseName.'.'.$this->logo->extension;
    }
}